<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="${pageContext.request.contextPath}/include/pageTitleBread.jsp"/>
<div id="page-content">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title">${pageInfo.innerTitle}</h3>
            </div>
            <form id="sysResForm" class="panel-body form-horizontal form-padding">
                <div class="form-group">
                    <label class="col-md-3 control-label">资源名称</label>
                    <div class="col-md-9">
                        <input type="text" name="flName" class="form-control">
                        <small class="help-block">*请输入资源名称</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源类型</label>
                    <div class="col-md-9">
                        <input id="fl_type_ml" class="magic-radio" type="radio" name="flType"
                               value="0" >
                        <label for="fl_type_ml">目录</label>
                        <input id="fl_type_cd" class="magic-radio" type="radio" name="flType"
                               value="1" checked>
                        <label for="fl_type_cd">菜单</label>
                        <input id="fl_type_an" class="magic-radio" type="radio" name="flType"
                               value="2">
                        <label for="fl_type_an">按钮</label>
                        <small class="help-block">请选择资源类型</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源访问路径</label>
                    <div class="col-md-9">
                        <input type="text" name="flUrl" class="form-control">
                        <small class="help-block">请输入资源访问路径</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源图标</label>
                    <div class="col-md-5">
                        <div class="input-group mar-btm">
                            <input type="text" id="icon" class="form-control" disabled>
                            <input type="hidden" id="fl_icon" name="flIcon">
                            <span class="input-group-btn">
                            <button class="btn btn-mint" type="button"
                                    onclick="selectIcon()">选择
                            </button>
                        </span>
                        </div>
                        <small class="help-block">请选择资源图标</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源权限标识</label>
                    <div class="col-md-9">
                        <input type="text" name="flPerm" class="form-control">
                        <small class="help-block">请输入资源权限标识</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">父级资源</label>
                    <div class="col-md-5">
                        <div class="input-group mar-btm">
                            <input type="text" id="show" class="form-control" disabled>
                            <input type="hidden" id="fl_parent_id" name="flParentId">
                            <input type="hidden" id="fl_parent_name" name="flParentName">
                            <span class="input-group-btn">
			                            <button class="btn btn-mint" type="button"
                                                onclick="selectOneParent()">选择</button>
			                        </span>
                        </div>
                        <small class="help-block">请选择父级资源</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源排序值</label>
                    <div class="col-md-9">
                        <input type="text" name="flOrder" class="form-control">
                        <small class="help-block">请输入资源排序值(值越大越靠前)</small>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">资源状态</label>
                    <div class="col-md-9">
                        <input id="fl_status_normal" class="magic-radio" type="radio" name="flStatus" value="0" checked>
                        <label for="fl_status_normal">正常</label>
                        <input id="fl_status_ex" class="magic-radio" type="radio" name="flStatus" value="1">
                        <label for="fl_status_ex">禁用</label>
                        <small class="help-block">请选择资源状态</small>
                    </div>
                </div>
                <div class="panel-footer">
                    <div class="row">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button class="btn btn-warning" type="reset">重置</button>
                            <button class="btn btn-mint" type="submit">保存</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script>

    function selectOneParent() {
        layer.open({
            type: 2,
            title: "选择父级菜单",
            area: ['300px', '450px'],
            content: "/sysRes/treeView"
        });
    }

    function loadUpMenu(parentId, parentName) {
        $("#fl_parent_id").val(parentId);
        $("#fl_parent_name").val(parentName);
        $("#show").val(parentName);
    }

    function save() {
        var data = common_ajax.ajaxFunc("/sysRes/saveOrUpdate", $('#sysResForm').serialize(), "json", null);
        if (data.code === 0) {
            pointLion.alertMsg("保存成功!", "success", "small", function () {
                doPjax(ctx + '/sysRes');//跳转到列表页
            });
        } else {
            pointLion.alertMsg("操作失败!", "danger", "small", function () {
                doPjax(ctx + '/sysRes');//跳转到列表页
            });
        }
    }

    function selectIcon() {
        layer.open({
            type: 2,
            title: '图标列表',
            content: ctx + '/sysRes/iconView',
            area: ['70%', '80%']
        });
    }

    $(document).ready(function () {
        $('#sysResForm').bootstrapValidator({
            excluded: [":hidden"],//关键配置，表示只对于隐藏域不进行验证，其他的表单元素都要验证
            fields: {
                "flCode": {
                    validators: {
                        notEmpty: {
                            message: '*角色代码不能为空!'
                        },
                        stringLength: {
                            min: 2,
                            message: '*角色代码必须大于两位'
                        }
                    }
                },
                "flName": {
                    validators: {
                        notEmpty: {
                            message: '*角色名称不能为空'
                        },
                        stringLength: {
                            min: 2,
                            message: '*角色名称必须大于两位'
                        }
                    }
                }
            }
        }).on("success.form.bv", function (e) {
            save();
            return false;//阻止表单跳转
        });
    });
</script>
